//
//  JkmTitleView.swift
//  SinaWb
//
//  Created by Jiang on 5/16/16.
//  Copyright © 2016 Jiang. All rights reserved.
//

import UIKit

class JkmTitleButton: UIButton {
    /**
            ### 初始化首页按钮 ###
     
     - parameter title:    首页标题
     - parameter target:   监听对象
     - parameter selector: 监听犯法
     
     - returns: 首页按钮
     */
    init(title : String ,target : UIViewController , selector : Selector){
        
        super.init(frame: CGRectZero)
        
        setImage(UIImage(named: "navigationbar_arrow_up"), forState: .Normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: .Selected)
        
        setTitle(title, forState: .Normal)
        setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        setTitleColor(UIColor.orangeColor(), forState: .Selected)
        
        addTarget(target, action: selector, forControlEvents: .TouchUpInside)
        
        sizeToFit()
    }
    
    /**
            交换imageView和tilteLable的位置
     */
    override func layoutSubviews() {
        super.layoutSubviews()
        ///Swift中可以直接设置结构体的参数
        // 交换imageView和tilteLable的位置
        imageView?.frame.origin.x = (titleLabel?.frame.size.width)!
        titleLabel?.frame.origin.x = 0
    }
    

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
